package cn.hzh.forward.init;

import cn.hzh.forward.service.ding.UserDinger;
import com.github.jaemon.dinger.DingerSender;
import com.github.jaemon.dinger.core.entity.DingerRequest;
import com.github.jaemon.dinger.core.entity.DingerResponse;
import com.github.jaemon.dinger.core.entity.ImageTextDeo;
import com.github.jaemon.dinger.core.entity.LinkDeo;
import com.github.jaemon.dinger.core.entity.enums.MessageSubType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@Component
public class DingDingInit {
    @Autowired
    private DingerSender dingerSender;
    @Autowired
    private UserDinger userDinger;

    private static final Logger log = LoggerFactory.getLogger(DingDingInit.class);

//    @PostConstruct
    public void didingInit() throws Exception {
        log.info("dinger init...");
        // 发送用户自定义消息
        sendUserDinger();
        // 发送text类型消息
        DingerResponse send = dingerSender.send(
                MessageSubType.TEXT,
                DingerRequest.request("Hello World, Hello Dinger")
        );

        // 发送markdown类型消息
        dingerSender.send(
                MessageSubType.MARKDOWN,
                DingerRequest.request("Hello World, Hello Dinger", "启动通知")
        );

        String picUrl = "https://jlfiles-test.jilianyun.cn/jlcloud/tenant/mainbody/image/DEFAULT_LOGO.png";
        List<ImageTextDeo> images = new ArrayList<>();
        images.add(
                ImageTextDeo.instance(
                        "联系我们", "https://jlfiles-test.jilianyun.cn/jlcloud/tenant/mainbody/1253241576096808962/image/87291c8998f3eb1a1f149141fb1db8de.png/", picUrl
                )
        );
        images.add(
                ImageTextDeo.instance(
                        "企业荣誉", "https://jlfiles-test.jilianyun.cn/jlcloud/tenant/mainbody/1253241576096808962/image/bf42e3aff1bbca8ae4482ab9d0c5a7a0.png", picUrl
                )
        );

        // 发送图文类型消息
        userDinger.imageText(images);


        // 发送link类型消息， 只支持钉钉
        userDinger.link(
                LinkDeo.instance(
                        "消息抓取",
                        "钉钉消息转发连接测试",
                        "https://open.dingtalk.com/document/group/custom-robot-access",
                        picUrl
                )
        );
    }


    // 发送用户自定义消息
    private void sendUserDinger () {
        userDinger.success("贵杰");
        userDinger.failed(1, "黄浩");
    }


}